package com.koron.plan.web.patrollineplan.controller;


import com.github.pagehelper.PageInfo;
import com.koron.bean.base.Response;
import com.koron.bean.plan.patrol.dto.PatrolDto;
import com.koron.bean.query.PageQuery;
import com.koron.common.core.config.ThreadLocalContext;
import com.koron.plan.web.patrollineplan.bean.dto.PlanLinePatrolDTO;
import com.koron.plan.web.patrollineplan.bean.dto.PlanLinePatrolItemDTO;
import com.koron.plan.web.patrollineplan.bean.po.PlanLinePatrol;
import com.koron.plan.web.patrollineplan.bean.query.PlanLinePatrolQuery;
import com.koron.plan.web.patrollineplan.service.PlanLinePatrolService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.koron.ebs.mybatis.ADOConnection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 线路巡视计划(PlanLinePatrol)表控制层
 *
 * @author jzp
 * @since 2022-11-24 14:24:31
 */
@Api(tags = "线路巡视计划接口")
@RestController
@RequestMapping("planLinePatrol")
public class PlanLinePatrolController {
    /**
     * 服务对象
     */
    @Autowired
    private PlanLinePatrolService planLinePatrolService;

    private String getCurrDs() {
        return ThreadLocalContext.get().getCurrDs();
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/selectOne")
    @ApiOperation("根据巡视计划id查询详情")
    public Response<PlanLinePatrolDTO> selectOne(@RequestParam String id) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), planLinePatrolService, "getDtoById", PlanLinePatrolDTO.class, id));
    }

    @GetMapping("/queryDetailByPatrolPointId")
    @ApiOperation("根据巡视线路查询巡视设备信息")
    public Response<List<PlanLinePatrolItemDTO>> queryDetailByPatrolPointId(String patrolPointId) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), planLinePatrolService, "queryDetailByPatrolPointId", List.class, patrolPointId));
    }



    @GetMapping("/queryList")
    @ApiOperation("巡视计划列表")
    public Response<PageInfo<PlanLinePatrol>> page(PageQuery pageQuery, PlanLinePatrolQuery query) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), planLinePatrolService, "page", PageInfo.class, pageQuery, query));
    }

    @PostMapping("/saveOrUpdate")
    @ApiOperation("保存或更新巡视计划")
    public Response<PlanLinePatrolDTO> saveOrUpdate( @Validated @RequestBody PlanLinePatrolDTO plan) {
        ADOConnection.runTask(getCurrDs(), planLinePatrolService, "saveDto", Boolean.class, plan);
        return Response.succ(plan);
    }

    @GetMapping("/startOrStop")
    @ApiOperation("启用/停止巡视计划")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "巡视计划id", required = true, dataType = "String"),
            @ApiImplicitParam(name = "startOrStop", value = "启动或停止标志，startOrStop = true，启用巡视计划。startOrStop = false，停用巡视计划", required = true, dataType = "Boolean")
    })
    public Response<PlanLinePatrolDTO> startOrStop(@RequestParam String id, @RequestParam boolean startOrStop) {
        return Response.succ(ADOConnection.runTask(getCurrDs(), planLinePatrolService, "startOrStop", PlanLinePatrolDTO.class, id, startOrStop));
    }

    @GetMapping("/issue")
    @ApiOperation("下发巡视计划，生成工单")
    @ApiImplicitParam(name = "id", value = "巡视计划id", required = true, dataType = "String")
    public Response<PlanLinePatrolDTO> issue(@RequestParam String id) {
        return Response.succ(ADOConnection.runTask(getCurrDs(), planLinePatrolService, "issue", PlanLinePatrolDTO.class, id));
    }

    @DeleteMapping("/deleteById")
    @ApiOperation("根据id删除巡视计划")
    @ApiImplicitParam(name = "planId", value = "巡视计划id", required = true, dataType = "String")
    public Response<Boolean> deleteById(@RequestParam String planId) {
        return Response.succ(ADOConnection.runTask(getCurrDs(), planLinePatrolService, "deleteById", Boolean.class, planId));
    }


    @GetMapping("/getPlanPatrolMsg")
    @ApiOperation("通过计划的Id,获取计划生成工单需要的所有信息")
    @ApiImplicitParam(name = "planId", value = "巡视计划id", required = true, dataType = "String")
    public Response<PatrolDto> getPlanPatrolMsg(@RequestParam String planId, @RequestParam String planCreateTime) {
        return Response.succ(ADOConnection.runTask(getCurrDs(), planLinePatrolService, "getPlanPatrolMsg", PatrolDto.class, planId,planCreateTime));
    }

}
